home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 03 - 1987 / 03.11 Nov 87 / C string library / PStrLib Source / PStrDraw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-10-21  |  1.2 KB  |  39 lines  |  [TEXT/KAHL]

  1. /*    FILE:  PStrDraw.c
  2.     Draws 1 to 10 Pascal strings at specified locations in the 
  3.     current GrafPort.  It Offers auto-centering and New-Line modes.
  4.     If h == 0 then it uses the last (current) h position.
  5.     If v == 0 then it uses the last (current) v position.
  6.     If x < 0 then s is centered inside the portRect.  If y < 0 then
  7.     then it offsets -y number of lines from current v pos.
  8.     Otherwise, h and v represent the desired x and y coordinates. */
  9. #include    "PStrLib.h"
  10.  
  11. PStrDraw(count, s, h, v)
  12. int        count;    /* number of { s, h, v} sets to follow */
  13. char    *s;        /* a pascal string to draw */
  14. int        h;        /* horizontal position */
  15. int        v;        /* vertical position */
  16. {    
  17.     register    char    *argPtr = (char *)&count;
  18.     register    char    *sp;
  19.     register    Rect    *rp = &thePort->portRect;
  20.     register    int        x, y, lineHeight = 1.5 * thePort->txSize;
  21.     static        int        old_x = 0, old_y = 0;
  22.     
  23.     while (--count >= 0) {
  24.         sp = *(char **)(argPtr += 2);
  25.         x = *(int *)(argPtr += 4);
  26.         y = *(int *)(argPtr += 2);
  27.         if (x >= 0)    
  28.             old_x = x;
  29.         else if (x != CUR)    /* Auto-Center Mode? */
  30.             old_x = (rp->right - rp->left - StringWidth(sp)) / 2;
  31.         if (y >= 0)
  32.             old_y = y;
  33.         else if (y != CUR)    /* New-Line Mode? */
  34.             old_y += -y * lineHeight;
  35.         MoveTo(old_x, old_y);
  36.         DrawString(sp);
  37.         old_x += StringWidth(sp);
  38.     }
  39. }